<?php

namespace app\index\service;

use app\admin\dao\AxbConsultingRecordDao;
use app\admin\dao\AxbRecordDao;
use app\common\model\AccountBill;
use app\common\model\AccountUser;
use app\common\model\Member;
use app\common\model\Trade;
use app\common\model\UserPersonnel;
use app\index\traits\PaymentProxyTrait;
use app\index\traits\PaymentTrait;
use ary\Ary;
use ShidianUtil\Concurrent\Synchronizer;
use ShidianUtil\Utils\ConvertUtil;
use ShidianUtil\Utils\StringUtil;
use ShidianUtil\Utils\TimeUtil;
use think\facade\Log;

/**
 * AXB通话结果处理
 * Class ConsultingAxbResultCallbackService
 * @package app\index\service
 */
class ConsultingAxbResultCallbackService
{
    use PaymentTrait;
    use PaymentProxyTrait;

    private AxbConsultingRecordDao $axbConsultingRecordDao;

    public function __construct(AxbConsultingRecordDao $axbConsultingRecordDao)
    {

        $this->axbConsultingRecordDao = $axbConsultingRecordDao;
    }

    /**
     * AXB通话结束回调（实际处理）
     * @param array $params
     * @return void
     */
    public function handle(array $params): void
    {

        // 去重
        try {
            $params['consultingId'] = $params['tradeId'] ?? '';

            $record = $this->axbConsultingRecordDao->insertActive($params);

            $record = $record->toArray();

        } catch (\Exception $exception) {
            // 插入失败可能是通话记录ID重复了
            return;
        }

        // 这里一定是通过成功结束，而不是没接通等情况


        if (!isset($params['consultingId']) || !isset($params['memberId'])) {
            Log::error('Consulting AXB回调处理参数错误，参数：' . ConvertUtil::jsonEncode($params));
            return;
        }

        // 处理回调
        // $this->handleCard($params, $record);
    }

}
